package 离婚登记数和粗离婚率之比.Bean;

import org.apache.hadoop.io.WritableComparable;
import org.jetbrains.annotations.NotNull;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

public class DivorceAnalysisBean implements WritableComparable<DivorceAnalysisBean> {
    private String year;
    private String province;//省份

    public DivorceAnalysisBean(){

    }

    public DivorceAnalysisBean(String year,String province){
        this.year = year;
        this.province = province;
    }

    public void set(String year,String province){
        this.year = year;
        this.province = province;
    }

    public String getYear() { return year; }

    public void setYear(String year) { this.year = year; }

    public String getProvince() { return province; }

    public void setProvince(String province) { this.province = province; }

    @Override
    public String toString() {
        return year + "\t" + province;
    }

    @Override
    public void write(DataOutput dataOutput) throws IOException {
        dataOutput.writeUTF(year);
        dataOutput.writeUTF(province);
    }

    @Override
    public void readFields(DataInput dataInput) throws IOException {
        this.year = dataInput.readUTF();
        this.province = dataInput.readUTF();
    }

    @Override
    public int compareTo(@NotNull DivorceAnalysisBean o) {

        int res = this.year.compareTo(o.getYear());
        if(res == 0){
            res = this.province.compareTo(o.getProvince());
            return res;
        }

        return res;
    }
}
